using ASP;
using HoWave.Common;
using HoWave.Data;
using HoWave.Data.Bll;
using HoWave.Data.Model;
using HoWave.Web.Admin;
using System;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Admin_MBF_UserGiftCardCategoryEdit : Admin, IRequiresSessionState
{
	protected HiddenField h_id;
	protected DropDownList ddl_FestivalName;
	protected RequiredFieldValidator rfv1;
	protected TextBox txtTitle;
	protected RequiredFieldValidator rfv2;
	protected HiddenField h_Pictrue;
	protected Image Image_Pictrue;
	protected FileUpload FileUpload_Pictrue;
	protected Button ButtonRemovefile;
	protected Literal ltr_Pictrue;
	protected Button Add;
	protected Button ButtonReturn;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!this.Page.IsPostBack)
		{
			if (!base.admin.CheckAdminPower(39))
			{
				base.WriteLog("Modidy", Language.GetAdminMsg("Log/Access", "0"), "MBF_UserGiftCardCategoryEdit");
				base.WriteRightErrMsg();
			}
			this.ddl_FestivalName.bindTableToDropDownList(Blls.bllFestival.GetDropDownListData(""), true, false);
			int iD = Fetch.GetID("id");
			if (iD > 0)
			{
				this.ShowInfo(iD);
			}
		}
	}
	private void ShowInfo(int id)
	{
		UserGiftCardCategoryModel model = Blls.bllGiftCategory.GetModel((long)id);
		this.h_id.Value = model.id.ToString();
		this.ddl_FestivalName.ddlSelect(model.FestivalName);
		this.txtTitle.Text = model.Title;
		this.h_Pictrue.Value = model.Picture;
		this.Image_Pictrue.ImageUrl = "~/UpLoadFile/VIPCardPic/" + model.Picture;
	}
	protected void ButtonReturn_Click(object sender, EventArgs e)
	{
		base.Response.Redirect("MBF_UserGiftCardCategorySet.aspx?MenuID=5&page=" + Fetch.Get("page") + "&MenuName=网站&FileName=VIP卡面值管理#pos_" + this.h_id.Value);
	}
	protected void Add_Click(object sender, EventArgs e)
	{
		string text = "";
		if (this.ddl_FestivalName.SelectedIndex == 0)
		{
			text += "请选择节日！\\n";
		}
		if (this.txtTitle.Text.Trim() == "")
		{
			text += "请填写标题！\\n";
		}
		if (text != "")
		{
			MessageBox.Show(this, text);
		}
		else
		{
			string selectValue = this.ddl_FestivalName.GetSelectValue(new string[0]);
			string text2 = this.txtTitle.Text;
			string text3 = "";
			if (this.FileUpload_Pictrue.HasFile)
			{
				UploadFile uploadFile = new UploadFile("~/UpLoadFile/VIPCardPic");
				uploadFile.Extension = ".png,.jpg,.gif";
				string text4 = uploadFile.DoUploadFile(this.FileUpload_Pictrue, true, new string[0]);
				if (text4 == "")
				{
					if (this.Image_Pictrue.ImageUrl != "")
					{
						FileIO.DelecteFile(base.Server.MapPath(this.Image_Pictrue.ImageUrl));
					}
					text3 = uploadFile.FileName;
				}
				else
				{
					this.ltr_Pictrue.Text = text4;
				}
			}
			else
			{
				text3 = this.h_Pictrue.Value;
			}
			if (text3.Trim() == "")
			{
				MessageBox.Show(this, "请选择一张图片！");
			}
			else
			{
				UserGiftCardCategoryModel userGiftCardCategoryModel = new UserGiftCardCategoryModel();
				userGiftCardCategoryModel.FestivalName = selectValue;
				userGiftCardCategoryModel.Title = text2;
				userGiftCardCategoryModel.Picture = text3;
				if (this.h_id.Value == "")
				{
					Blls.bllGiftCategory.Add(userGiftCardCategoryModel);
				}
				else
				{
					userGiftCardCategoryModel.id = new long?((long)int.Parse(this.h_id.Value));
					Blls.bllGiftCategory.Update(userGiftCardCategoryModel);
				}
				this.Image_Pictrue.ImageUrl = "~/UpLoadFile/VIPCardPic/" + userGiftCardCategoryModel.Picture;
				MessageBox.ShowAndRedirect(this, "保存成功！", string.Concat(new object[]
				{
					"MBF_UserGiftCardCategorySet.aspx?MenuID=5&page=",
					Fetch.Get("page"),
					"&MenuName=网站&FileName=VIP卡面值管理#pos_",
					userGiftCardCategoryModel.id
				}));
			}
		}
	}
}
